package com.dycc.libary.router_interceptor;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by wxk on 2018/1/21 0021.
 */

public class InterceptorBind implements Serializable {
    private List<Bind> interceptors = new ArrayList<>();

    public Bind checkBind(Class<?> interceptor) {
        for (Bind bind : interceptors) {
            if (bind.getInterceptor() != null && bind.getInterceptor().equals(interceptor)) {
                return bind;
            }
        }
        return null;
    }


    public InterceptorBind addInterceptor(Bind bind) {
        boolean flag=BaseInterceptor.class.isAssignableFrom(bind.interceptor);
        if (bind != null && bind.interceptor != null
                && BaseInterceptor.class.isAssignableFrom(bind.interceptor)) {
            interceptors.add(bind);
        } else {
            throw new UnsupportedOperationException("无效拦截器");
        }
        return this;
    }


    public static class Bind implements  Serializable{
        private Class interceptor;
        private boolean enable = true;
        private Object obj;


        public Bind(Class interceptor, boolean enable) {
            this.interceptor = interceptor;
            this.enable = enable;
        }

        public Bind() {
        }

        public Bind(Class interceptor) {
            this.interceptor = interceptor;
        }

        public Bind(Class interceptor, boolean enable, Object obj) {
            this.interceptor = interceptor;
            this.enable = enable;
            this.obj = obj;
        }

        public Class getInterceptor() {
            return interceptor;
        }

        public void setInterceptor(Class interceptor) {
            this.interceptor = interceptor;
        }

        public boolean isEnable() {
            return enable;
        }

        public void setEnable(boolean enable) {
            this.enable = enable;
        }

        public Object getObj() {
            return obj;
        }

        public void setObj(Object obj) {
            this.obj = obj;
        }
    }

}
